package com.nbrc.jsonmodel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.activiti.engine.history.HistoricProcessInstance;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.nbrc.helper.DateSerializer;

public class MyProcess{
	private String id;
	private String businessKey;
	private String processDefinitionId;
	@JsonSerialize(using=DateSerializer.class)
	private Date startTime;
	@JsonSerialize(using=DateSerializer.class)
	private Date endTime;
	private Long durationInMillis;
	private String startActivityId;
	private String deleteReason;
	private String superProcessInstanceId;
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBusinessKey() {
		return businessKey;
	}

	public void setBusinessKey(String businessKey) {
		this.businessKey = businessKey;
	}

	public String getProcessDefinitionId() {
		return processDefinitionId;
	}

	public void setProcessDefinitionId(String processDefinitionId) {
		this.processDefinitionId = processDefinitionId;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Long getDurationInMillis() {
		return durationInMillis;
	}

	public void setDurationInMillis(Long durationInMillis) {
		this.durationInMillis = durationInMillis;
	}

	public String getStartActivityId() {
		return startActivityId;
	}

	public void setStartActivityId(String startActivityId) {
		this.startActivityId = startActivityId;
	}

	public String getDeleteReason() {
		return deleteReason;
	}

	public void setDeleteReason(String deleteReason) {
		this.deleteReason = deleteReason;
	}

	public String getSuperProcessInstanceId() {
		return superProcessInstanceId;
	}

	public void setSuperProcessInstanceId(String superProcessInstanceId) {
		this.superProcessInstanceId = superProcessInstanceId;
	}
	




	public  static MyProcess toProcess(HistoricProcessInstance hpi) {
		MyProcess p = new MyProcess();
		p.setBusinessKey(hpi.getBusinessKey());
		p.setDeleteReason(hpi.getDeleteReason());
		p.setDurationInMillis(hpi.getDurationInMillis());
		p.setEndTime(hpi.getEndTime());
		p.setId(hpi.getId());
		p.setProcessDefinitionId(hpi.getProcessDefinitionId());
		p.setStartActivityId(hpi.getStartActivityId());
		p.setStartTime(hpi.getStartTime());
		return p;
	}
	public  static List<MyProcess> toProcess(List<HistoricProcessInstance> lt) {
		List<MyProcess> lp = new ArrayList<>();
		for(HistoricProcessInstance hpi : lt){
			lp.add(MyProcess.toProcess(hpi));
		}
		return lp;
	}
	
}
